package com.neusoft.elm.controller;

import com.neusoft.elm.po.DeliveryAddress;
import com.neusoft.elm.service.DeliveryAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/DeliveryAddressController")
public class DeliveryAddressController {
    @Autowired
    private DeliveryAddressService deliveryAddressService;
    @RequestMapping("/listDeliveryAddressByUserId")
    public Object listDeliveryAddressByUserId(String userId){
        DeliveryAddress deliveryAddress = new DeliveryAddress();
        deliveryAddress.setUserId(userId);
        List<DeliveryAddress> deliveryAddressList = deliveryAddressService.listDeliveryAddressByUserId(userId);
        return deliveryAddressList;
    }
    @RequestMapping("/saveDeliveryAddress")
    public Object saveDeliveryAddress(DeliveryAddress deliveryAddress){

        try {
            int i = deliveryAddressService.saveDeliveryAddress(deliveryAddress);
            return i;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
    @RequestMapping("/removeDeliveryAddress")
    public Object removeDeliveryAddress(Integer daId){
        int i = deliveryAddressService.removeDeliveryAddress(daId);
        return i;
    }
    @RequestMapping("/getDeliveryAddressById")
    public Object getDeliveryAddressById(Integer daId){
        DeliveryAddress deliveryAddress=new DeliveryAddress();
        deliveryAddress.setDaId(daId);
        DeliveryAddress deliveryAddress1 = deliveryAddressService.getDeliveryAddressById(deliveryAddress.getDaId());
        return deliveryAddress1;
    }
    @RequestMapping("/updateDeliveryAddress")
    public Object updateDeliveryAddress(DeliveryAddress deliveryAddress){
return deliveryAddressService.updateDeliveryAddress(deliveryAddress);
    }
}
